@extends('admin.layout.homeindex')
@section('content')
<div id="page-content" class="single-page">
	<div class="container">
		<div class="row">
			<div class="col-lg-12">
				<ul class="breadcrumb">
					<li><a href="{{url('/')}}">首页</a></li>
					<li><a href="category.html">类别</a></li>
					<li><a href="">{{$goods->pname}}</a></li>
				</ul>
			</div>
		</div>
		<div class="row">
			<div id="main-content" class="col-md-8">
				<div class="product">
					<div class="col-md-6">
						<div class="image">
							<img src="{{$goods->pic}}"/>
							<div class="image-more">
								 <ul class="row">
									 <li class="col-lg-3 col-sm-3 col-xs-4">
										<a href=""><img class="img-responsive" src="/HO/images/s7-1.png"></a>
									</li>
									 <li class="col-lg-3 col-sm-3 col-xs-4">
										<a href=""><img class="img-responsive" src="/HO/images/s7-2.png"></a>
									</li>
									 <li class="col-lg-3 col-sm-3 col-xs-4">
										<a href=""><img class="img-responsive" src="/HO/images/s7-3.png"></a>
									</li>
									 <li class="col-lg-3 col-sm-3 col-xs-4">
										<a href=""><img class="img-responsive" src="/HO/images/s7-4.png"></a>
									</li>
								</ul>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="caption">
							<div class="name"><h3>{{$goods->title}}</h3></div>
							<div class="info">
								<ul>
									<li>品牌:{{$goods->pname}}</li>
								</ul>
							</div>
							<div class="price">{{$goods->price}}<span>6000</span></div>
							<div class="rating"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span></div>
							<!-- 添加到购物车的数量 -->
							<form action="/cart/insert" class="cart" method="post" enctype="multipart/form-data">	
								<div class="well">	
									<label>数量: </label> 
										{{csrf_field()}}
										<button type="button" class="goods_d btn btn-default"> - </button>
										<input class="goods_num" type="text" name="num" value="1" style="width:40px">
										<button type="button" class="goods_a btn btn-default"> + </button>
									<label>库存: </label>{{$goods->kucun}}
								</div>
								<input type="hidden" name="id" value="{{$goods->id}}">
								<button type="button" class="addcart btn btn-primary btn-icon ">加入购物车</button></br>
							</form>
							<!-- 添加提醒 -->
							<div class="alert alert-info addseccess" style="display:none;" >
                                已加入购物车
                            </div>	
						</div>
					</div>
					<div class="clear"></div>
				</div>	
				<div class="product-desc">
						<ul class="nav nav-tabs">
							<li class="active"><a href="description">描述</a></li>
							<li><a href="">评论</a></li>
						</ul>
						<div class="tab-content">
							<div id="description" class="tab-pane fade in active">
								{!!$goods->content!!}
							</div>
							<div id="review" class="tab-pane fade">
							  <div class="review-text">
								<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
							  </div>
							  <div class="review-form">
								<h4>Write a review</h4>
								<form name="form1" id="ff" method="post" action="review.php">
									<label>
									<span>Enter your name:</span>
									<input type="text"  name="name" id="name" required>
									</label>
									<label>
									<span>Your message here:</span>
									<textarea name="message" id="message"></textarea>
									</label>
									<div class="text-right">
										<input class="btn btn-default" type="reset" name="reset" value="Reset">
										<input class="btn btn-default" type="submit" name="Submit" value="Submit">
									</div>
								</form>
							  </div>
							</div>
						</div>
				</div>
				<div class="product-related">
					<div class="heading"><h2>相关产品</h2></div>
					<div class="products">
					@foreach($categoods as $k => $v)
						<div class="col-lg-4 col-md-4 col-xs-12">
							<div class="product">
								<div class="image"><a href="{{$v->id}}"><img src="{{$v->pic}}" /></a></div>
								<div class="buttons">
									<a class="btn cart" href=""><span class="glyphicon glyphicon-shopping-cart"></span></a>
									<a class="btn wishlist" href=""><span class="glyphicon glyphicon-heart"></span></a>
									<a class="btn compare" href=""><span class="glyphicon glyphicon-transfer"></span></a>
								</div>
								<div class="caption">
									<div class="name"><h3>{{$v->title}}</h3></div>
									<div class="price">{{$v->price}}</div>
									<div class="rating"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span></div>
								</div>
							</div>
						</div>
					@endforeach
					</div>
					<div class="clear"></div>
				</div>
			</div>
			<div id="sidebar" class="col-md-4">
				<!-- 遍历品牌 -->
				<div class="widget wid-brand">
					<div class="heading"><h4>手机品牌</h4></div>
					@foreach($cates as $k => $v)
					<div class="content">
						<b><a href="{{url('/category')}}/{{$v -> id}}">{{$v -> cname}}</a></b>
					</div>
					@endforeach
				</div>
				<!-- 遍历最新产品 -->
				<div class="widget wid-product">
					<div class="heading"><h4>最新产品</h4></div>
					<div class="content">
					@foreach($news as $k => $v)
						<div class="product">
							<a href="{{url('/product')}}/{{$v -> id}}"><img src="{{$v -> pic}}" /></a>
							<div class="wrapper">
								<h5><a href="{{url('/product')}}/{{$v -> id}}">{{$v -> title}}</a></h5>
								<div class="price">{{$v -> price}}</div>
								<div class="rating"><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star"></span><span class="glyphicon glyphicon-star-empty"></span></div>
							</div>
						</div>
					@endforeach		
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$('.goods_d').click(function(){
		//获取商品数量 转成int
		var num = parseInt($('.goods_num').val());
		//计算
		num = num - 1;
		//判断最小值为1
		if(num == 0) return;
		//更新赋值
		$('.goods_num').val(num);
		});
	$('.goods_a').click(function(){
		//获取商品数量
		var num = parseInt($('.goods_num').val());
		//计算
		num = num + 1;
		//更新赋值
		$('.goods_num').val(num);
	});

	//给button绑定单击时间
	$('.addcart').click(function(){
		var id =$('.cart').find('input[name=id]').val();
		var num =$('.cart').find('input[name=num]').val();
		
	//准备发送ajax
	$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
	});
	
	//发送
    $.post('/cart/insert',{id:id,num:num},function(data){
    	if(data == 1){
    		//添加成功
    		$('.addseccess').show(1000);
    		setTimeout(function(){
    			$('.addseccess').hide(1000);
    		},2000)
    	}else{
    		alert('请先登录');
    	}

    })
	});


	
</script>
@endsection('content')